﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace SocialKlee.BusinessLogicLayer
{

    /// <summary>
    /// Summary description for BOLyer
    /// </summary>
    public class BOLyer
    {
        public BOLyer()
        {
            //
            // TODO: Add constructor logic here
            //
        }

        public static DataTable GetDataTable(string Query)
        {
            DataTable dtbl = SocialKlee.DataAccessLayer.DALayer.GetDataTable(Query);
            return dtbl;
        }

        public static string ExecuteStoreProcedure(string SPname, string[] strNamef, string[] strValueF)
        {
            string error = "";
            if ((strNamef.Length == null) && (strValueF.Length == null))
            {
                return "Not Required Length";
            }
            if (strNamef.Length != strValueF.Length)
            {
                throw new ArgumentException("Parameters does not match");

            }
            if ((strValueF.Length > 0) && (strValueF != null))
            {
                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.CommandText = SPname;
                for (int i = 0; i < strValueF.Length; i++)
                {
                    object obj;
                    if (strValueF[i] == null)
                    {
                        obj = DBNull.Value;
                    }
                    else
                    {
                        obj = strValueF[i].ToString();
                    }
                    sqlCommand.Parameters.AddWithValue(strNamef[i].ToString(), obj);
                }
                error = SocialKlee.DataAccessLayer.DALayer.ExecuteStoreProcedure(ConfigurationManager.AppSettings["ConnectionString"], sqlCommand);
                return error;

            }
            return error;
        }
        public static DataTable GetDataTable(string spName, string[] strName, string[] strValue)
        {
            DataTable dt = null;

            if ((strName.Length == null) || (strValue == null))
            {
                // return "Not Required Length";    
            }

            if (strName.Length != strValue.Length)
            {
                throw new ArgumentException("Parameter count does not Match");

            }

            if ((strValue != null) && (strValue.Length > 0))
            {

                SqlCommand sqlCommand = new SqlCommand();
                sqlCommand.CommandType = CommandType.StoredProcedure;
                sqlCommand.CommandText = spName;
                for (int i = 0; i <= strValue.Length - 1; i++)
                {
                    sqlCommand.Parameters.AddWithValue(strName[i].ToString(), strValue[i].ToString());
                }
                dt = SocialKlee.DataAccessLayer.DALayer.GetDataTableProc(ConfigurationManager.AppSettings["ConnectionString"], sqlCommand);
                return dt;
            }
            return dt;
        }
    }
}